{% load helpers %}
{% load i18n %}

<div class="card">
  <h2 class="card-header">
    {% trans "Inventory Items" %}
    {% if perms.dcim.add_inventoryitem %}
      <div class="card-actions">
        <a href="{% url 'dcim:inventoryitem_add' %}?device={{ object.device.pk }}&component_type={{ object|content_type_id }}&component_id={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-ghost-primary btn-sm">
          <span class="mdi mdi-plus-thick" aria-hidden="true"></span> {% trans "Add Inventory Item" %}
        </a>
      </div>
    {% endif %}
  </h2>
  <table class="table table-hover">
    <thead>
      <tr>
        <th>{% trans "Name" %}</th>
        <th>{% trans "Label" %}</th>
        <th>{% trans "Role" %}</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      {% for item in object.inventory_items.all %}
        <tr>
          <td>{{ item|linkify:"name" }}</td>
          <td>{{ item.label|placeholder }}</td>
          <td>{{ item.role|linkify|placeholder }}</td>
          <td class="text-end d-print-none">
            {% if perms.dcim.change_inventoryitem %}
              <a href="{% url 'dcim:inventoryitem_edit' pk=item.pk %}?return_url={{ object.get_absolute_url }}" class="btn btn-sm btn-warning" title="{% trans "Edit" %}">
                <i class="mdi mdi-pencil" aria-hidden="true"></i>
              </a>
            {% endif %}
            {% if perms.ipam.delete_inventoryitem %}
              <a href="{% url 'dcim:inventoryitem_delete' pk=item.pk %}?return_url={{ object.get_absolute_url }}" class="btn btn-sm btn-danger" title="{% trans "Delete" %}">
                <i class="mdi mdi-trash-can-outline" aria-hidden="true"></i>
              </a>
            {% endif %}
          </td>
        </tr>
      {% empty %}
        <tr>
          <td colspan="5" class="text-muted">{% trans "None" %}</td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
</div>
